# -*- coding: utf-8 -*-

def do_upgrade(env, cursor):
    try:
        name = env.project_name
    except:
        pass

    # TODO: name can be undefined!

    # check if the default forum already exists
    cursor.execute("SELECT COUNT(id) FROM forum WHERE name = %s", name)
    for row in cursor:
        if int(row[0]) > 0:
            return

    # create the default forum
    cursor.execute("INSERT INTO forum (name, time, forum_group, author, "
                   "moderators, subscribers, subject, description) "
                   "VALUES (%s, UNIX_TIMESTAMP(NOW()), 0, 'trac', '', '', %s, %s)",
                   (name, name, name))
